package cn.zymall.merchant.service.impl;

import cn.zymall.common.model.Merchant;
import cn.zymall.common.model.ShopMainCategories;
import cn.zymall.common.model.StoreType;
import cn.zymall.common.utils.redis.RedisUtil;
import cn.zymall.merchant.mapper.MerchantAccountMapper;
import cn.zymall.merchant.mapper.MerchantMapper;
import cn.zymall.merchant.service.MerchantService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.catalina.Store;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @ClassName MerchantServiceImpl
 * @Description TODO
 * @Author chenmei
 * @Date 2020/8/17 20:04
 * @Version 1.0
 **/
@Service
public class MerchantServiceImpl extends ServiceImpl<MerchantMapper, Merchant> implements MerchantService {

	@Autowired
	RedisUtil redisUtil;

	@Override
	/**
	 * 返回店铺的所有类型
	 * @Author: chenmei
	 * @param
	 * @Date: 2020/8/19 20:34
	 * @return: storeTypes
	 **/
	public List<Object> getAllMerchantType() {
		List<Object> storeTypes=null;
      try{
	      boolean k=redisUtil.hasKey("merchantAllType");
	       storeTypes=redisUtil.lGet("merchantAllType",0,-1);
	      if(!k||storeTypes.size()==0){
		      List<StoreType> allType=baseMapper.getAllMerchantType();
		      redisUtil.lSet("merchantAllType",allType);
	      }
	      storeTypes=redisUtil.lGet("merchantAllType",0,-1);
      }catch (RuntimeException r){
      	r.getMessage();
      }finally {

      }
		return storeTypes;


	}

	/**
	 * 返回所有的店铺主营类目
	 * @Author: chenmei
	 * @Date: 2020/8/21 22:59
	 * @return: shopMainCategories
	 **/
	@Override
	public List<Object> getMainCategories() {
		boolean k=redisUtil.hasKey("shopMainCategories");
		List<Object> shopMainCategories=redisUtil.lGet("shopMainCategories",0,-1);
		if(!k|| shopMainCategories.size()==0){
			List<ShopMainCategories> allshopMainCateGories=baseMapper.getMainCategories();
			redisUtil.lSet("shopMainCategories",allshopMainCateGories);

		}
		shopMainCategories=redisUtil.lGet("shopMainCategories",-1,0);
		return shopMainCategories;

	}

	/*@Override
	*//**
	 * 根据店铺关键字获取店铺
	 * @Author: chenmei
	 * @param key	关键字
	 * @param index	 开始行
	 * @param rows	 条数
	 * @Date: 2020/8/17 15:59
	 * @return:  userIPage 返回店铺
	 **//*
	public IPage<Merchant> searchKey(String key, Integer index, Integer rows) {
		*//*QueryWrapper<Merchant> queryWrapper = new QueryWrapper<>();
		queryWrapper.like("merchantKeyword",key);
		Page<Merchant> page = new Page<>(index, rows);
		IPage<Merchant> userIPage =merchantMapper.selectPage(page, queryWrapper);

		return userIPage;*//*
		return null;
	}*/
}
